package com.kfm.jdbc.day0329;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.invoke.VarHandle;
import java.util.Arrays;

public class Demo02 {

    public static void main(String[] args) {
//        new FileInputStream(new File("D:\\test.txt"));
        try (FileInputStream fis = new FileInputStream("D:\\io\\test.txt");){

            System.out.println(fis.available()); // 读取文件的字节数
            // 读取一个字节
            int read = fis.read();
            System.out.println(read); // 97

            System.out.println(fis.available()); // 读取文件的字节数

            // 定义一个 byte 数组
//            byte[] bytes = new byte[5];
//            int read1 = fis.read(bytes); // 读取 5 个字节放到数组中
//            System.out.println(read1); // 3
//            System.out.println(Arrays.toString(bytes)); // [98, 99, 100, 0, 0]

            fis.skip(1);

            int read1 = fis.read();
            System.out.println(read1);
//            byte[] bytes = new byte[5];
//            int read1 = fis.read(bytes, 1, 3); // 读取 5 个字节放到数组中 从下标 1 开始放，放 3 个
//
//            System.out.println(Arrays.toString(bytes)); // [0, 98, 99, 100, 0


        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
